package diff.tests;

import java.util.List;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.Iterator;
import java.io.StringReader;
import java.io.DataInputStream;
import java.io.FileInputStream;

/**
 * Simple helper class for storing text and obtaining it from file. 
 *
 * @author Arseny Kapoulkine
 */
public class Text
{
    private List contents;

    /**
     * Default ctor, leaves text empty.
     */
    public Text()
    {
        contents = new ArrayList();
    }

    /**
     * Ctor from string list.
     *
     * @param contents - string list
     */
    public Text(List contents)
    {
        this.contents = contents;
    }

    /**
     * Loads text from specified file.
     *
     * @param file - file name
     */
    public Text(String file)
    {
        contents = new ArrayList();

        try
        {
            FileInputStream stream = new FileInputStream(file);
            DataInputStream in = new DataInputStream(stream);

            while (in.available() != 0)
                contents.add(in.readLine());

            in.close();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    /**
     * Output file to console (for debug purposes only).
     */
    public void debugPrint()
    {
        int line = 0;

        for (Iterator it = contents.iterator(); it.hasNext(); )
        {
            System.out.print(line);
            System.out.print(": ");
            System.out.println((String)it.next());

            ++line;
        }
    }

    /**
     * Contents accessor.
     *
     * @return contents
     */
    public List getContents()
    {
        return contents;
    }
}
